﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:loc="clr-namespace:AscendViewer">

	<!-- Content node -->
	<DataTemplate DataType="{x:Type loc:ContentNodeViewModel}">
		<Grid HorizontalAlignment="Left">
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="*"/>
			</Grid.RowDefinitions>

			<!-- Main node display -->
			<Button Command="{Binding SelectCommand}" Focusable="False">
				<Button.InputBindings>
					<MouseBinding Command="{Binding LookAtCommand}" MouseAction="LeftDoubleClick"/>
				</Button.InputBindings>
				<Button.Template>
					<ControlTemplate>
						<Grid HorizontalAlignment="Left">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="20"/>
								<ColumnDefinition Width="Auto"/>
								<ColumnDefinition Width="Auto"/>
							</Grid.ColumnDefinitions>

							<!-- Expansion ToggleButton -->
							<ToggleButton x:Name="PART_ExpandToggle" Grid.Column="0" IsChecked="{Binding IsExpanded}"
										  HorizontalAlignment="Center">
								<ToggleButton.Template>
									<ControlTemplate>
										<Grid x:Name="PART_Grid" Background="Transparent">
											<Path x:Name="PART_Arrow" Data="M 0,8L 7,8L 7,1L 0,8 Z " Fill="DimGray"
												  Stroke="DimGray" StrokeThickness="0.5" VerticalAlignment="Center"
												  HorizontalAlignment="Center"/>
										</Grid>

										<ControlTemplate.Triggers>
											<DataTrigger Binding="{Binding IsExpanded}" Value="False">
												<Setter TargetName="PART_Arrow" Property="Fill" Value="WhiteSmoke"/>
												<Setter TargetName="PART_Arrow" Property="LayoutTransform">
													<Setter.Value>
														<RotateTransform Angle="-45" CenterX="0" CenterY="8"/>
													</Setter.Value>
												</Setter>
											</DataTrigger>
											<Trigger SourceName="PART_Grid" Property="IsMouseOver" Value="True">
												<Setter TargetName="PART_Arrow" Property="StrokeThickness" Value="0.8"/>
											</Trigger>
										</ControlTemplate.Triggers>
									</ControlTemplate>
								</ToggleButton.Template>
							</ToggleButton>

							<!-- Colored square -->
							<Border x:Name="PART_ColorSquare" Grid.Column="1" Width="12" Height="12" CornerRadius="1"
								Background="Gray" Margin="0,0,-2,0"/>

							<!-- Node text -->
							<TextBlock x:Name="PART_Text" Grid.Column="2" Text="{Binding SelfAsString}" Foreground="DimGray"
								   HorizontalAlignment="Left" Padding="7,4"/>
						</Grid>

						<ControlTemplate.Triggers>
							<DataTrigger Binding="{Binding IsSelected}" Value="True">
								<Setter TargetName="PART_Text" Property="FontWeight" Value="Bold"/>
							</DataTrigger>
							<DataTrigger Binding="{Binding CanExpand}" Value="False">
								<Setter TargetName="PART_ExpandToggle" Property="Visibility" Value="Collapsed"/>
							</DataTrigger>
							<DataTrigger Binding="{Binding Type}" Value="{x:Type loc:ModelContentNodeViewModel}">
								<Setter TargetName="PART_ColorSquare" Property="Background" Value="#45A3FF"/>
							</DataTrigger>
							<DataTrigger Binding="{Binding Type}" Value="{x:Type loc:AnimatedContentNodeViewModel}">
								<Setter TargetName="PART_ColorSquare" Property="Background" Value="#9F81CB"/>
							</DataTrigger>
							<DataTrigger Binding="{Binding Type}" Value="{x:Type loc:ArmatureContentNodeViewModel}">
								<Setter TargetName="PART_ColorSquare" Property="Background" Value="#4DC34D"/>
							</DataTrigger>
							<DataTrigger Binding="{Binding Type}" Value="{x:Type loc:BoneContentNodeViewModel}">
								<Setter TargetName="PART_ColorSquare" Property="Background" Value="#73CF83"/>
							</DataTrigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Button.Template>
			</Button>

			<!-- Child nodes -->
			<ItemsControl x:Name="PART_Children" Grid.Row="1" ItemsSource="{Binding Children}" Margin="18,0,0,0"/>
		</Grid>

		<DataTemplate.Triggers>
			<DataTrigger Binding="{Binding IsExpanded}" Value="False">
				<Setter TargetName="PART_Children" Property="Visibility" Value="Collapsed"/>
			</DataTrigger>
		</DataTemplate.Triggers>
	</DataTemplate>
</ResourceDictionary>
